home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 September / maximum-cd-2009-09.iso / DiscContents / Firefox Setup 3.0.7.exe / nonlocalized / chrome / toolkit.jar / content / mozapps / extensions / list.js < prev    next >
Encoding:
Text File  |  2008-03-27  |  7.3 KB  |  190 lines

  1. //@line 39 "/e/fx19rel/WINNT_5.2_Depend/mozilla/toolkit/mozapps/extensions/content/list.js"
  2.  
  3. const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  4. const kDialog = "dialog";
  5.  
  6. /**
  7.  * This dialog can be initialized from parameters supplied via window.arguments
  8.  * or it can be used to display blocklist notification and blocklist blocked
  9.  * installs via nsIDialogParamBlock as is done by nsIExtensionManager.
  10.  *
  11.  * When using this dialog with window.arguments it must be opened modally, the
  12.  * caller can inspect the user action after the dialog closes by inspecting the
  13.  * value of the |result| parameter on this object which is set to the dlgtype
  14.  * of the button used to close the dialog.
  15.  * 
  16.  * window.arguments[0] is an array of strings to display in the tree. If the
  17.  * array is empty the tree will not be displayed.
  18.  * window.arguments[1] a JS Object with the following properties:
  19.  * 
  20.  * title:    A title string, to be displayed in the title bar of the dialog.
  21.  * message1: A message string, displayed above the addon list
  22.  * message2: A message string, displayed below the addon list
  23.  * message3: A bolded message string, displayed below the addon list
  24.  * moreInfoURL: An url for displaying more information
  25.  * iconClass  : Can be one of the following values (default is alert-icon)
  26.  *              alert-icon, error-icon, or question-icon
  27.  *
  28.  * If no value is supplied for message1, message2, message3, or moreInfoURL,
  29.  * the element is not displayed.
  30.  *
  31.  * buttons: {
  32.  *  accept: { label: "A Label for the Accept button",
  33.  *            focused: true },
  34.  *  cancel: { label: "A Label for the Cancel button" },
  35.  *  ...
  36.  * },
  37.  *
  38.  * result:  The dlgtype of button that was used to dismiss the dialog. 
  39.  */
  40.  
  41. var gButtons = { };
  42.  
  43. function init() {
  44.   var de = document.documentElement;
  45.   var items = [];
  46.   if (window.arguments[0] instanceof Components.interfaces.nsIDialogParamBlock) {
  47.     var args = window.arguments[0];
  48.     var fromInstall = args.GetInt(0) == 1 ? true : false;
  49.     var numberOfItems = args.GetInt(1);
  50.     for (var i = 0; i < numberOfItems; ++i)
  51.       items.push(args.GetString(i));
  52.  
  53.     var extensionsBundle = document.getElementById("extensionsBundle");
  54.     try {
  55.       var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
  56.                                 .getService(Components.interfaces.nsIURLFormatter);
  57.       var url = formatter.formatURLPref("extensions.blocklist.detailsURL");
  58.     }
  59.     catch (e) { }
  60.  
  61.     if (fromInstall) { // Blocklist blocked install
  62.       var params = {
  63.         message1: extensionsBundle.getFormattedString("blocklistedInstallMsg",
  64.                                                       [items[0]]),
  65.         moreInfoURL: url,
  66.         title: extensionsBundle.getString("blocklistedInstallTitle")
  67.       };
  68.       items = [];
  69.       var button = document.getElementById("centeredButton");
  70.       button.setAttribute("dlgtype", "accept");
  71.       de.buttons = "accept";
  72.       de.getButton("accept").focus();
  73.     }
  74.     else { // Blocklist background notification
  75.       // only hide when not used due to focus issues
  76.       document.getElementById("buttonCenteredBox").hidden = true;
  77.       var brandBundle = document.getElementById("brandBundle");
  78.       var brandShortName = brandBundle.getString("brandShortName");
  79.       params = {
  80.         message1: extensionsBundle.getFormattedString("blocklistNotifyMsg2",
  81.                                                       [brandShortName]),
  82.         message2: extensionsBundle.getFormattedString("blocklistRestartMsg2",
  83.                                                       [brandShortName]),
  84.         moreInfoURL: url,
  85.         title: extensionsBundle.getString("blocklistNotifyTitle2")
  86.       };
  87.       de.buttons = "extra1,cancel";
  88.       button = de.getButton("cancel");
  89.       button.label = extensionsBundle.getString("laterButton");
  90.       de.setAttribute("ondialogextra1", "restartApp();");
  91.       button.focus();
  92.       button = de.getButton("extra1");
  93.       button.label = extensionsBundle.getFormattedString("restartButton",
  94.                                                          [brandShortName]);
  95.     }
  96.   }
  97.   else {
  98.     // only hide when not used due to focus issues
  99.     document.getElementById("buttonCenteredBox").hidden = true;
  100.     items = window.arguments[0];
  101.     params = window.arguments[1];
  102.   }
  103.  
  104.   var addons = document.getElementById("addonsChildren");
  105.   if (items.length > 0)
  106.     document.getElementById("addonsTree").hidden = false;
  107.  
  108.   // Fill the addons list
  109.   for (i = 0; i < items.length; ++i) {
  110.     var treeitem = document.createElementNS(kXULNS, "treeitem");
  111.     var treerow  = document.createElementNS(kXULNS, "treerow");
  112.     var treecell = document.createElementNS(kXULNS, "treecell");
  113.     treecell.setAttribute("label", items[i]);
  114.     treerow.appendChild(treecell);
  115.     treeitem.appendChild(treerow);
  116.     addons.appendChild(treeitem);
  117.   }
  118.  
  119.   // Set the messages
  120.   var messages = ["message1", "message2", "message3"];
  121.   for (i = 0; i < messages.length; ++i) {
  122.     if (messages[i] in params) {
  123.       var message = document.getElementById(messages[i]);
  124.       message.hidden = false;
  125.       message.appendChild(document.createTextNode(params[messages[i]]));
  126.     }
  127.   }
  128.   
  129.   document.getElementById("infoIcon").className =
  130.     params["iconClass"] ? "spaced " + params["iconClass"] : "spaced alert-icon";
  131.  
  132.   if ("moreInfoURL" in params && params["moreInfoURL"]) {
  133.     message = document.getElementById("moreInfo");
  134.     message.value = extensionsBundle.getString("moreInfoText");
  135.     message.setAttribute("href", params["moreInfoURL"]);
  136.     document.getElementById("moreInfoBox").hidden = false;
  137.   }
  138.  
  139.   // Set the window title
  140.   if ("title" in params)
  141.     document.title = params.title;
  142.  
  143.   // Set up the buttons
  144.   if ("buttons" in params) {
  145.     gButtons = params.buttons;
  146.     var buttonString = "";
  147.     for (var buttonType in gButtons)
  148.       buttonString += "," + buttonType;
  149.     de.buttons = buttonString.substr(1);
  150.     for (buttonType in gButtons) {
  151.       button = de.getButton(buttonType);
  152.       button.label = gButtons[buttonType].label;
  153.       if (gButtons[buttonType].focused)
  154.         button.focus();
  155.       document.addEventListener(kDialog + buttonType, handleButtonCommand, true);
  156.     }
  157.   }
  158. }
  159.  
  160. function shutdown() {
  161.   for (buttonType in gButtons)
  162.     document.removeEventListener(kDialog + buttonType, handleButtonCommand, true);
  163. }
  164.  
  165. function restartApp() {
  166.   const nsIAppStartup = Components.interfaces.nsIAppStartup;
  167.   // Notify all windows that an application quit has been requested.
  168.   var os = Components.classes["@mozilla.org/observer-service;1"]
  169.                      .getService(Components.interfaces.nsIObserverService);
  170.   var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  171.                              .createInstance(Components.interfaces.nsISupportsPRBool);
  172.   os.notifyObservers(cancelQuit, "quit-application-requested", null);
  173.  
  174.   // Something aborted the quit process. 
  175.   if (cancelQuit.data)
  176.     return;
  177.  
  178.   Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
  179.             .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
  180. }
  181.  
  182. /**
  183.  * Watch for the user hitting one of the buttons to dismiss the dialog
  184.  * and report the result back to the caller through the |result| property on
  185.  * the arguments object.
  186.  */
  187. function handleButtonCommand(event) {
  188.   window.arguments[1].result = event.type.substr(kDialog.length);
  189. }
  190.